package cn.zifangsky.model;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.http.HttpStatus;

/**
 * @Author guoyb
 * @Date 2023/10/24  10:45
 */
@Data
public class ResponseVO<T>  {

    @ApiModelProperty(value = "响应内容")
    private T data;

    @ApiModelProperty(value = "状态码", name = "code", example = "200")
    private int code;

    @ApiModelProperty(value = "响应信息")
    private String message;

    public ResponseVO(T data, int code, String message) {
        this.data = data;
        this.code = code;
        this.message = message;
    }

    public static <T> ResponseVO<T> ok(T data) {
        return new ResponseVO(data, HttpStatus.SC_OK, "操作成功");
    }

    public static <T> ResponseVO<T> valiFail(String message) {
        return new ResponseVO(message, HttpStatus.SC_BAD_REQUEST, "参数校验不通过");
    }
    public static <T> ResponseVO<T> error(String message) {
        return new ResponseVO(null, HttpStatus.SC_INTERNAL_SERVER_ERROR, message);
    }

}
